<template>
<el-dialog title="入库" :close-on-click-modal="false" :visible.sync="visible" width="90%">
    <el-table :data="dataForm.bookList" border style="width: 100%;">
        <el-table-column prop="img" header-align="center" align="center" label="封面" width="120">
            <template slot-scope="scope">
                <img v-if="scope.row.imgUrl" style="width: 100px; height: 100px" :src="scope.row.imgUrl" />
                <span v-else></span>
            </template>
        </el-table-column>
        <el-table-column prop="name" header-align="center" align="center" label="图书名称"></el-table-column>
        <el-table-column prop="type" header-align="center" align="center" label="分类" width="50"></el-table-column>
        <el-table-column prop="isbn" header-align="center" align="center" label="ISBN" width="130"></el-table-column>
        <el-table-column prop="author" header-align="center" align="center" label="作者"></el-table-column>
        <el-table-column prop="press" header-align="center" align="center" label="出版社"></el-table-column>
        <el-table-column prop="publishDate" header-align="center" align="center" label="出版时间" width="100">
            <template slot-scope="scope">{{scope.row.publishDate | formatYearMonth}}</template>
        </el-table-column>
        <el-table-column prop="language" header-align="center" align="center" label="语言" width="50"></el-table-column>
        <el-table-column prop="price" header-align="center" align="center" label="定价" width="80">
            <template slot-scope="scope">￥{{scope.row.price | formatPrice}}</template>
        </el-table-column>
        <el-table-column prop="num" header-align="center" align="center" label="入库数量" width="80">
        </el-table-column>
        <el-table-column prop="storeName" header-align="center" align="center" label="入库仓库" width="80">
        </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确认入库</el-button>
    </span>
</el-dialog>
</template>

<script>
export default {
    data() {
        return {
            visible: false,
            dataForm: {
                id: 0,
                orderId: '',
                bookDetailId: '',
                operator: '',
                operateDate: '',
                storeId: ''
            },
        }
    },
    methods: {
        init(data) {
            console.log(data)
            this.dataForm = data;
            this.visible = true;
            this.dataForm.bookList.forEach(function (item) {
                if (item.img) {
                    item.imgUrl =
                        "http://localhost:8080/wenyuan/generator/tbook/img/" + item.id;
                }
            });
        },
        // 表单提交
        dataFormSubmit() {
            this.$http({
                url: this.$http.adornUrl(`/generator/tputin/putin/` + this.dataForm.id),
                method: 'post'
            }).then(({
                data
            }) => {
                if (data && data.code === 0) {
                    this.$message({
                        message: '入库成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                            this.visible = false
                            this.$emit('refreshDataList')
                        }
                    })
                } else {
                    this.$message.error(data.msg)
                }
            })
        }
    }
}
</script>
